/**
 * Copyright (c) 2010, Slawomir Mazur <mazursllawek@gmail.com>
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions 
 * are met:
 * 
 * o Redistributions of source code must retain the above copyright notice, 
 *   this list of conditions and the following disclaimer.
 * o Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * o Neither the name of the Softisland nor the names of its contributors
 *   may be used to endorse or promote products derived from this software
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/**
 * Enter description here...
 *
 * @package     js
 * @copyright   Slawomir Mazur (c) 2010 (http://www.zend.com/zce.php?c=ZEND011643)
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @author      Slawomir Mazur <mazursllawek@gmail.com>
 */

function nowTime(separator)
{
	var _date = new Date();
	var sep = (separator)? separator : ':';
	
	_h = _date.getHours();
	_m = _date.getMinutes();
	_s = _date.getSeconds();
	
	if (_h < 10) _h = '0' + _h;
	if (_m < 10) _m = '0' + _m;
	if (_s < 10) _s = '0' + _s;
	
	return _h + sep + _m + sep + _s;
}

function now(separator)
{
	var _date = new Date();
	var sep = (separator)? separator : '-';
	
	_d = _date.getDate();
	_m = _date.getMonth() + 1;
	_y = _date.getFullYear();
	
	if (_d < 10) _d = '0' + _d; 
	if (_m < 10) _m = '0' + _m;
	
	return _d + sep + _m + sep + _y;
}

function setLocation(url)
{
    window.location.href = url;
}

$(document).ready(function() {
	var forms = [];
	
	for (i = 0; i < forms.length; i++) {
		$('form' + forms[i] + ' input[type="radio"]').css({ margin: '0 3px 0 7px', verticalAlign: 'text-top' });
		$('form' + forms[i] + ' input[type="text"]').css({ width: '344px' });
		$('form' + forms[i] + ' input[type="password"]').css({ width: '344px' });
		$('form' + forms[i] + ' select').css({ width: '350px' });
		$('form' + forms[i] + ' textarea').css({ width: '345px' });
	}
	
	$('a.popup-link').click(function() {
		window.open($(this).attr('href'));
		return false;
	});	

	$('#emptyValuesSwitcher input').change(function() {
		if ($(this).attr('checked')) {
			$('li.emptyvalue').css({ display: 'none' });
		} else {
			$('li.emptyvalue').removeAttr('style');
		}
	})
	
	// accordion for multi queries
	var tabsHead = $('#multiquery-accordion .multiquery-slice h3');
	var tabsBody = $('#multiquery-accordion .multiquery-slice div.q-content');
	var speed = 0;
	var duration = 290;
	
	tabsBody.css({ display:'none' });
	
	jQuery.each(tabsHead, function(index, value) {
		var desc;
		var thiss = $(this);
		
		$(value).click(function() {						
			if (thiss.attr('class') == 'selected') {				
				thiss.next().hide(speed, function() {					
					thiss.html(desc);
					thiss.removeAttr('class');
					thiss.css({ opacity: .55 });
				});				
			} else {
				desc = thiss.html();
				thiss.html('&raquo;' + desc);
				thiss.addClass('selected');
				thiss.removeAttr('style');
				thiss.next().show(speed);
			}
		});
		
		$(value).hover(
			function() {
				if ($(this).attr('class') == 'selected') return;
				
				$(this).stop().animate({ opacity: .55, paddingLeft: 33 }, duration);
			},
			function() {
				if ($(this).attr('class') == 'selected') return;
				
				$(this).stop().animate({ opacity: 1, paddingLeft: 25 }, duration, function() { $(this).removeAttr('style'); });
			}
		);
	});
});